package com.smec.moblie.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;

import com.smec.moblie.R;
import com.smec.moblie.view.datepicker.CalendarPickerView;

import java.util.Calendar;
import java.util.Date;


public class MyDatePicker extends Dialog implements CalendarPickerView.OnDateSelectedListener {

	private CalendarPickerView calendar;
	private SubmitOperateDialogListener dialogListener;

	public interface SubmitOperateDialogListener {
		public void onDateSelected(Date date);

		public void onDateUnselected(Date date);

	}

	public MyDatePicker(Context context, SubmitOperateDialogListener listener) {
		super(context);
		dialogListener = listener;
	}

	public MyDatePicker(Context context, int theme,
			SubmitOperateDialogListener listener) {
		super(context, theme);
		dialogListener = listener;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_mydatepicker);

		initViews();
	}

	private void initViews() {
		final Calendar nextYear = Calendar.getInstance();
		nextYear.add(Calendar.YEAR, 1);
		final Calendar lastYear = Calendar.getInstance();
		lastYear.add(Calendar.YEAR, -1);

		calendar = (CalendarPickerView) findViewById(R.id.datepicker);
		calendar.init(lastYear.getTime(), nextYear.getTime()) //
				.inMode(CalendarPickerView.SelectionMode.SINGLE) //
				.withSelectedDate(new Date());
		calendar.setOnDateSelectedListener(this);
	}

	@Override
	public void onDateSelected(Date date) {
		dialogListener.onDateSelected(date);
	}

	@Override
	public void onDateUnselected(Date date) {
		dialogListener.onDateUnselected(date);

	}

}
